package lianxi;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-03-29
 * Time: 19:21
 */

/**
 * 全排列
 */
public class Main18 {
    static int []st = new int[10];
    static int []used = new int[10];
    static int n;
    public static void dfs(int u) {
        if(u>n) {
            for(int i=1;i<=n;i++) {
                System.out.print(st[i]+" ");
            }
            System.out.println();
            return ;
        }
        //遍历每个分支
        for(int i=1;i<=n;i++) {
            if(used[i] != 1) {
                st[u] = i;
                used[i] = 1;
                dfs(u+1);
                st[u] = 0;
                used[i] = 0;
            }
        }
    }
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        dfs(1);
    }
}
